#!/usr/bin/env sh

sleep 1
echo "Small Response Body:"
curl http://localhost:8080/
echo "\n\nEmpty Response:"
curl http://localhost:8080/empty
echo "\n\nBody Too Large:"
curl -H'Content-Length: 4000000000' http://localhost:8080/
echo "\n\nEcho Body:"
curl -XPOST http://localhost:8080/echo -d'Echo test'
echo "\n\nGet Header:"
curl http://localhost:8080/host
echo "\n\nChunked Response:"
curl http://localhost:8080/chunked
echo "\n\nChunked Response keep-alive:"
curl http://localhost:8080/chunked http://localhost:8080/chunked
echo "\n\nChunked Response close:"
curl -H'Connection: close' http://localhost:8080/chunked http://localhost:8080/chunked
echo "\n\nChunked Request keep-alive: (expect empty)"
dd if=/dev/urandom of=test.dat bs=262144 count=1 2> /dev/null
curl -H'Expect:' -H'Transfer-Encoding: chunked' -XPOST --data-binary @test.dat -o r1.dat http://localhost:8080/chunked-req -o r2.dat http://localhost:8080/chunked-req
diff r1.dat test.dat
diff r2.dat test.dat
echo "\n\nChunked Request close: (expect empty)"
curl -H'Expect:' -H'Transfer-Encoding: chunked' -XPOST --data-binary @test.dat -o r3.dat http://localhost:8080/chunked-req -o r4.dat http://localhost:8080/chunked-req
diff r3.dat test.dat
diff r4.dat test.dat
echo "\n\nPoll Server:"
curl http://localhost:8081/ &
sleep 1
curl http://localhost:8080/poll
sleep 1
curl http://localhost:8080/poll
echo "\n\nIterate Headers:"
curl -H'User-Agent: test-ua' -H'Foo-Header: foo-bar' http://localhost:8080/headers
echo "\nStress Test keep-alive:"
ab -k -c 200 -n 100000 http://127.0.0.1:8080/ > keep-alive.bench
cat keep-alive.bench | grep Complete
cat large-file.bench | grep Non-2xx
cat keep-alive.bench 1>&2
echo "\nStress Test close:"
ab -c 20 -n 1000 http://127.0.0.1:8080/ > connection-close.bench
cat connection-close.bench | grep Complete
cat large-file.bench | grep Non-2xx
cat connection-close.bench 1>&2
echo "\nStress Test large body:"
dd if=/dev/urandom of=test.dat bs=8388608 count=1 2> /dev/null
ab -c 2 -n 10 -p test.dat http://127.0.0.1:8080/echo > large-file.bench
cat large-file.bench | grep Complete
cat large-file.bench | grep Non-2xx
cat large-file.bench 1>&2
rm *.dat *.bench
